<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" integrity="sha256-dABdfBfUoC8vJUBOwGVdm8L9qlMWaHTIfXt+7GnZCIo=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/black/pace-theme-flat-top.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous" defer></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"tryhub.top","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.23.0","exturl":false,"sidebar":{"position":"left","width_expanded":320,"width_dual_column":240,"display":"post","padding":18,"offset":12},"hljswrap":true,"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":true,"color":"#222","save":"manual"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"duration":200,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.json","localsearch":{"enable":true,"top_n_per_article":1,"unescape":true,"preload":true,"trigger":"auto"}}</script><script src="/js/config.js" defer></script>

    <meta name="description" content="关于 Linux 内核Linux 内核分两种：官方内核（通常是内核开发人员用）和各大 Linux 发行版内核（一般用户常用）。">
<meta property="og:type" content="article">
<meta property="og:title" content="CentOS 7 升级 Linux 内核">
<meta property="og:url" content="https://tryhub.top/2022/01/08/CentOS-7-%E5%8D%87%E7%BA%A7-Linux-%E5%86%85%E6%A0%B8/index.html">
<meta property="og:site_name" content="奇姆的博客">
<meta property="og:description" content="关于 Linux 内核Linux 内核分两种：官方内核（通常是内核开发人员用）和各大 Linux 发行版内核（一般用户常用）。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-01-08T11:19:35.000Z">
<meta property="article:modified_time" content="2022-01-08T11:46:32.354Z">
<meta property="article:author" content="Jaron Chim">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="centOS">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://tryhub.top/2022/01/08/CentOS-7-%E5%8D%87%E7%BA%A7-Linux-%E5%86%85%E6%A0%B8/">


<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://tryhub.top/2022/01/08/CentOS-7-%E5%8D%87%E7%BA%A7-Linux-%E5%86%85%E6%A0%B8/","path":"2022/01/08/CentOS-7-升级-Linux-内核/","title":"CentOS 7 升级 Linux 内核"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>CentOS 7 升级 Linux 内核 | 奇姆的博客</title>
  

  <script src="/js/third-party/analytics/baidu-analytics.js" defer></script>
  <script async src="https://hm.baidu.com/hm.js?1ad13b7aff8bfe9206fa7e12d5c4a4f0"></script>







  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous" defer></script>
<script src="/js/utils.js" defer></script><script src="/js/motion.js" defer></script><script src="/js/sidebar.js" defer></script><script src="/js/next-boot.js" defer></script><script src="/js/bookmark.js" defer></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous" defer></script>
<script src="/js/third-party/search/local-search.js" defer></script>





  <script src="/js/third-party/pace.js" defer></script>


  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="奇姆的博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">奇姆的博客</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
      <div class="search-header">
        <span class="search-icon">
          <i class="fa fa-search"></i>
        </span>
        <div class="search-input-container">
          <input autocomplete="off" autocapitalize="off" maxlength="80"
                placeholder="搜索..." spellcheck="false"
                type="search" class="search-input">
        </div>
        <span class="popup-btn-close" role="button">
          <i class="fa fa-times-circle"></i>
        </span>
      </div>
      <div class="search-result-container">
        <div class="search-result-icon">
          <i class="fa fa-spinner fa-pulse fa-5x"></i>
        </div>
      </div>
    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%85%B3%E4%BA%8E-Linux-%E5%86%85%E6%A0%B8"><span class="nav-number">1.</span> <span class="nav-text">关于 Linux 内核</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%98%E6%96%B9%E5%86%85%E6%A0%B8"><span class="nav-number">1.1.</span> <span class="nav-text">官方内核</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Longterm-release-%E7%9A%84%E5%86%85%E6%A0%B8"><span class="nav-number">1.1.1.</span> <span class="nav-text">Longterm release 的内核</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%84%E5%A4%A7-Linux-%E5%8F%91%E8%A1%8C%E7%89%88%E5%86%85%E6%A0%B8"><span class="nav-number">1.2.</span> <span class="nav-text">各大 Linux 发行版内核</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E7%9A%84%E5%86%85%E6%A0%B8%E7%89%88%E6%9C%AC"><span class="nav-number">2.</span> <span class="nav-text">查看当前的内核版本</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%A6%82%E8%BF%B0"><span class="nav-number">2.1.</span> <span class="nav-text">概述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E6%9F%A5%E7%9C%8B%E5%86%85%E6%A0%B8%E4%BF%A1%E6%81%AF%E7%9A%84%E5%91%BD%E4%BB%A4"><span class="nav-number">2.2.</span> <span class="nav-text">常用的查看内核信息的命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#uname"><span class="nav-number">2.2.1.</span> <span class="nav-text">uname</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#proc-%E8%99%9A%E6%8B%9F%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F"><span class="nav-number">2.2.2.</span> <span class="nav-text">&#x2F;proc 虚拟文件系统</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%8D%87%E7%BA%A7%E5%86%85%E6%A0%B8"><span class="nav-number">3.</span> <span class="nav-text">升级内核</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%90%AF%E7%94%A8-ELRepo-%E4%BB%93%E5%BA%93"><span class="nav-number">3.1.</span> <span class="nav-text">启用 ELRepo 仓库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%8F%AF%E7%94%A8%E7%9A%84%E7%B3%BB%E7%BB%9F%E5%86%85%E6%A0%B8%E5%8C%85"><span class="nav-number">3.2.</span> <span class="nav-text">查看可用的系统内核包</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85%E6%9C%80%E6%96%B0%E5%86%85%E6%A0%B8"><span class="nav-number">3.3.</span> <span class="nav-text">安装最新内核</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE-grub2"><span class="nav-number">4.</span> <span class="nav-text">设置 grub2</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E7%B3%BB%E7%BB%9F%E4%B8%8A%E7%9A%84%E6%89%80%E6%9C%89%E5%8F%AF%E4%BB%A5%E5%86%85%E6%A0%B8"><span class="nav-number">4.1.</span> <span class="nav-text">查看系统上的所有可以内核</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AE-grub2-1"><span class="nav-number">4.2.</span> <span class="nav-text">设置 grub2</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-grub2-set-default-0-%E5%91%BD%E4%BB%A4%E8%AE%BE%E7%BD%AE"><span class="nav-number">4.2.1.</span> <span class="nav-text">通过 grub2-set-default 0 命令设置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BC%96%E8%BE%91-etc-default-grub-%E6%96%87%E4%BB%B6"><span class="nav-number">4.2.2.</span> <span class="nav-text">编辑 &#x2F;etc&#x2F;default&#x2F;grub 文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%94%9F%E6%88%90-grub-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%B9%B6%E9%87%8D%E5%90%AF"><span class="nav-number">4.3.</span> <span class="nav-text">生成 grub 配置文件并重启</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%AA%8C%E8%AF%81"><span class="nav-number">4.4.</span> <span class="nav-text">验证</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E6%97%A7%E5%86%85%E6%A0%B8-%E5%8F%AF%E9%80%89"><span class="nav-number">5.</span> <span class="nav-text">删除旧内核 (可选)</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-yum-remove-%E5%91%BD%E4%BB%A4"><span class="nav-number">5.1.</span> <span class="nav-text">通过 yum remove 命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-yum-utils-%E5%B7%A5%E5%85%B7"><span class="nav-number">5.2.</span> <span class="nav-text">通过 yum-utils 工具</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%89%E8%A3%85"><span class="nav-number">5.2.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4"><span class="nav-number">5.2.2.</span> <span class="nav-text">删除</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Jaron Chim"
      src="/images/jaron.gif">
  <p class="site-author-name" itemprop="name">Jaron Chim</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">76</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">95</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">144</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/admin-Jaron" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;admin-Jaron" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:tryhub@tryhub.top" title="E-Mail → mailto:tryhub@tryhub.top" rel="noopener me"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
        <div class="back-to-top animated" role="button" aria-label="返回顶部">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://tryhub.top/2022/01/08/CentOS-7-%E5%8D%87%E7%BA%A7-Linux-%E5%86%85%E6%A0%B8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/jaron.gif">
      <meta itemprop="name" content="Jaron Chim">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="奇姆的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="CentOS 7 升级 Linux 内核 | 奇姆的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          CentOS 7 升级 Linux 内核
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2022-01-08 19:19:35 / 修改时间：19:46:32" itemprop="dateCreated datePublished" datetime="2022-01-08T19:19:35+08:00">2022-01-08</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/linux/" itemprop="url" rel="index"><span itemprop="name">linux</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/linux/centOS/" itemprop="url" rel="index"><span itemprop="name">centOS</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><h1 id="关于-Linux-内核"><a href="#关于-Linux-内核" class="headerlink" title="关于 Linux 内核"></a>关于 Linux 内核</h1><p>Linux 内核分两种：官方内核（通常是内核开发人员用）和各大 Linux 发行版内核（一般用户常用）。</p>
<span id="more"></span>

<h2 id="官方内核"><a href="#官方内核" class="headerlink" title="官方内核"></a>官方内核</h2><p>在使用 Docker 时，发现其对 Linux 内核版本的最低要求是 3.10（这也刚好是 CentOS 7.2 的内核版本），但是在这个版本上有部分功能无法实现。目前 Linux 内核已经发布到 4.X（可以随时在 <a target="_blank" rel="noopener" href="https://www.kernel.org/">Linux内核官网</a> 查看当前版本），为了使用最新版本的内核，只好在安装 CentOS 7 后对内核进行升级。</p>
<p>当然，内核也不能选最新的，防止有尚未发现的 BUG。而且为了减少以后停止维护带来的麻烦，最好安装长期支持版本。各个版本的支持时间在 <a target="_blank" rel="noopener" href="https://www.kernel.org/category/releases.html">Linux内核档案</a> 查看。每个版本可能有四种类型，概述如下：</p>
<ul>
<li>Prepatch：Prepatch 或 “RC” 内核是主要的内核预发行版本，主要针对内核开发人员和 Linux 爱好者。必须从源代码进行编译，并且通常包含必须在可以放入稳定版本之前进行测试的新功能。Prepatch 内核由 Linus Torvalds 维护和发布。</li>
<li>Mainline：Mainline 主线树由 Linus Torvalds 维护。这个版本的内核会引入所有新功能。新的 Mainline 内核每 2-3 个月发布一次。</li>
<li>Stable：每个主线内核被发布后，即被认为是“stable”。任何对 stable 内核的 BUG 修复都会从 Mainline 主线树中回溯并由指定的 stable 内核维护人员使用。 在下一个主线内核可用之前，通常只有几个 BUG 修复内核版本 - 除非它被指定为“longterm maintenance kernel（长期维护内核）”。stable 内核更新按需发布，通常每月 2-3 次。</li>
<li>Longterm：通常会提供几个“longterm maintenance”内核版本，用于修复旧版内核的 BUG。这些内核只会修复重大 BUG，并且不会频繁发布版本。</li>
</ul>
<h3 id="Longterm-release-的内核"><a href="#Longterm-release-的内核" class="headerlink" title="Longterm release 的内核"></a>Longterm release 的内核</h3><table>
<thead>
<tr>
<th align="left">版本</th>
<th align="left">维护人</th>
<th align="left">发布日期</th>
<th align="left">项目生命周期</th>
</tr>
</thead>
<tbody><tr>
<td align="left">4.14</td>
<td align="left">Greg Kroah-Hartman</td>
<td align="left">2017-11-12</td>
<td align="left">Jan, 2020</td>
</tr>
<tr>
<td align="left">4.9</td>
<td align="left">Greg Kroah-Hartman</td>
<td align="left">2016-12-11</td>
<td align="left">Jan, 2019</td>
</tr>
<tr>
<td align="left">4.4</td>
<td align="left">Greg Kroah-Hartman</td>
<td align="left">2016-01-10</td>
<td align="left">Feb, 2022</td>
</tr>
<tr>
<td align="left">4.1</td>
<td align="left">Sasha Levin</td>
<td align="left">2015-06-21</td>
<td align="left">May, 2018</td>
</tr>
<tr>
<td align="left">3.16</td>
<td align="left">Ben Hutchings</td>
<td align="left">2014-08-03</td>
<td align="left">Apr, 2020</td>
</tr>
<tr>
<td align="left">3.2</td>
<td align="left">Ben Hutchings</td>
<td align="left">2012-01-04</td>
<td align="left">May, 2018</td>
</tr>
</tbody></table>
<h2 id="各大-Linux-发行版内核"><a href="#各大-Linux-发行版内核" class="headerlink" title="各大 Linux 发行版内核"></a>各大 Linux 发行版内核</h2><p>一般来说，只有从 <code>kernel.org</code> 下载并编译安装的内核才是官方内核。<br>大多数 Linux 发行版提供自行维护的内核，可以通过 yum 或 rpm 等包管理系统升级。这些内核可能不再和 Linux 内核官方开发维护人员有关系了。<strong>通过这个由各大 Linux 发行版支持的仓库升级内核，通常来说更简单可靠，但是可选择的内核版本也更少。</strong></p>
<p>使用 <code>uname -r</code> 区分你用的是官方内核还是 Linux 发行版内核，横线后面有任何东西都表示这不是官方内核：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># uname -r</span></span><br><span class="line">3.10.0-514.26.2.el7.x86_64</span><br></pre></td></tr></table></figure>

<h1 id="查看当前的内核版本"><a href="#查看当前的内核版本" class="headerlink" title="查看当前的内核版本"></a>查看当前的内核版本</h1><h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><p>Linux 只表示内核。各大 Linux 发行版（RedHat、Ubuntu、CentOS 等）在内核基础上集成了其他的一系列软件，按照各自的版本规则发布。例如 CentOS 7.2 中，通过 <code>uname -r</code> 查看内核版本时，会看到 <code>3.10.0-514.26.2.el7.x86_64</code>，表示对应的 Linux 内核版本是 3.10。</p>
<h2 id="常用的查看内核信息的命令"><a href="#常用的查看内核信息的命令" class="headerlink" title="常用的查看内核信息的命令"></a>常用的查看内核信息的命令</h2><h3 id="uname"><a href="#uname" class="headerlink" title="uname"></a>uname</h3><p>打印指定的系统信息。不带参数时，默认使用 <code>-s</code> 参数。</p>
<p>参数：<br>-a, –all：按照下面的顺序打印所有信息，如果 -p 和 -i 未知时排除掉。<br>-s, –kernel-name：打印内核名字，一般就是 Linux。<br>-n, –nodename：打印网络节点的主机名。<br>-r, –kernel-release：打印内核发行版的版本。常用。<code>3.10.0-514.26.2.el7.x86_64</code><br>-v, –kernel-version：打印内核的版本。<code>#1 SMP Tue Jul 4 15:04:05 UTC 2017</code><br>-m, –machine：打印机器硬件名。<br>-p, –processor：打印处理器名字或“unknown”。<br>-i, –hardware-platform：打印硬件平台或“unknown”。<br>-o, –operating-system：打印操作系统。<br>–help：显示这个帮助并退出。<br>–version：显示这版本信息并退出。</p>
<p>示例：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># uname -r</span></span><br><span class="line">3.10.0-514.26.2.el7.x86_64</span><br><span class="line"><span class="comment"># uname -a</span></span><br><span class="line">Linux VM_139_74_centos 3.10.0-514.26.2.el7.x86_64 <span class="comment">#1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux</span></span><br><span class="line"><span class="comment"># cat /etc/redhat-release </span></span><br><span class="line">CentOS Linux release 7.2.1511 (Core) </span><br></pre></td></tr></table></figure>

<h3 id="proc-虚拟文件系统"><a href="#proc-虚拟文件系统" class="headerlink" title="&#x2F;proc 虚拟文件系统"></a>&#x2F;proc 虚拟文件系统</h3><p>内核空间和用户空间通过 <code>/proc</code> 虚拟文件系统可以通信。</p>
<p><code>/proc</code> 目录中包含一些目录和虚拟文件，这些虚拟文件可以向用户呈现内核信息或者从用户空间向内核发送信息。</p>
<p>常用文件：</p>
<ul>
<li>cpuinfo：标识了处理器的类型和速度</li>
<li>pci：显示在 PCI 总线上找到的设备</li>
<li>modules：当前加载到内核中的模块</li>
<li>version：系统版本及内核版本</li>
</ul>
<p>示例：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># cat /proc/version </span></span><br><span class="line">Linux version 3.10.0-514.26.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) <span class="comment">#1 SMP Tue Jul 4 15:04:05 UTC 2017</span></span><br></pre></td></tr></table></figure>

<h1 id="升级内核"><a href="#升级内核" class="headerlink" title="升级内核"></a>升级内核</h1><p>记得首先更新仓库：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum -y update</span><br></pre></td></tr></table></figure>

<p><code>-y</code> 选项可以在每次需要确认时，自动使用 yes，节省时间。</p>
<h2 id="启用-ELRepo-仓库"><a href="#启用-ELRepo-仓库" class="headerlink" title="启用 ELRepo 仓库"></a>启用 ELRepo 仓库</h2><p>ELRepo 仓库是基于社区的用于企业级 Linux 仓库，提供对 RedHat Enterprise (RHEL) 和 其他基于 RHEL的 Linux 发行版（CentOS、Scientific、Fedora 等）的支持。<br>ELRepo 聚焦于和硬件相关的软件包，包括文件系统驱动、显卡驱动、网络驱动、声卡驱动和摄像头驱动等。</p>
<p>启用 ELRepo 仓库：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</span></span><br><span class="line"><span class="comment"># rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm</span></span><br></pre></td></tr></table></figure>

<h2 id="查看可用的系统内核包"><a href="#查看可用的系统内核包" class="headerlink" title="查看可用的系统内核包"></a>查看可用的系统内核包</h2><p>可以看到，只有 4.4 和 4.15 两个版本可以使用：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># yum --disablerepo=&quot;*&quot; --enablerepo=&quot;elrepo-kernel&quot; list available</span></span><br><span class="line">Loaded plugins: fastestmirror, langpacks</span><br><span class="line">elrepo-kernel                                                   | 2.9 kB  00:00:00     </span><br><span class="line">elrepo-kernel/primary_db                                        | 1.7 MB  00:00:02     </span><br><span class="line">Determining fastest mirrors</span><br><span class="line">* elrepo-kernel: elrepo.org</span><br><span class="line">Available Packages</span><br><span class="line">kernel-lt.x86_64                           4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-lt-devel.x86_64                     4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-lt-doc.noarch                       4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-lt-headers.x86_64                   4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-lt-tools.x86_64                     4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-lt-tools-libs.x86_64                4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-lt-tools-libs-devel.x86_64          4.4.118-1.el7.elrepo            elrepo-kernel</span><br><span class="line">kernel-ml.x86_64                           4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">kernel-ml-devel.x86_64                     4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">kernel-ml-doc.noarch                       4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">kernel-ml-headers.x86_64                   4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">kernel-ml-tools.x86_64                     4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">kernel-ml-tools-libs.x86_64                4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">kernel-ml-tools-libs-devel.x86_64          4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">perf.x86_64                                4.15.6-1.el7.elrepo             elrepo-kernel</span><br><span class="line">python-perf.x86_64</span><br></pre></td></tr></table></figure>

<h2 id="安装最新内核"><a href="#安装最新内核" class="headerlink" title="安装最新内核"></a>安装最新内核</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># yum --enablerepo=elrepo-kernel install kernel-ml</span></span><br></pre></td></tr></table></figure>

<p><code>--enablerepo</code> 选项开启 CentOS 系统上的指定仓库。默认开启的是 <code>elrepo</code>，这里用 <code>elrepo-kernel</code> 替换。</p>
<h1 id="设置-grub2"><a href="#设置-grub2" class="headerlink" title="设置 grub2"></a>设置 grub2</h1><p>内核安装好后，需要设置为默认启动选项并重启后才会生效</p>
<h2 id="查看系统上的所有可以内核"><a href="#查看系统上的所有可以内核" class="headerlink" title="查看系统上的所有可以内核"></a>查看系统上的所有可以内核</h2><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># sudo awk -F\&#x27; &#x27;$1==&quot;menuentry &quot; &#123;print i++ &quot; : &quot; $2&#125;&#x27; /etc/grub2.cfg</span></span><br><span class="line">0 : CentOS Linux (4.15.6-1.el7.elrepo.x86_64) 7 (Core)</span><br><span class="line">1 : CentOS Linux (3.10.0-514.26.2.el7.x86_64) 7 (Core)</span><br><span class="line">2 : CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)</span><br><span class="line">3 : CentOS Linux (0-rescue-f9d400c5e1e8c3a8209e990d887d4ac1) 7 (Core)</span><br></pre></td></tr></table></figure>

<h2 id="设置-grub2-1"><a href="#设置-grub2-1" class="headerlink" title="设置 grub2"></a>设置 grub2</h2><p>机器上存在 4 个内核，我们要使用 4.15 这个版本，可以通过 grub2-set-default 0 命令或编辑 &#x2F;etc&#x2F;default&#x2F;grub 文件来设置。</p>
<h3 id="通过-grub2-set-default-0-命令设置"><a href="#通过-grub2-set-default-0-命令设置" class="headerlink" title="通过 grub2-set-default 0 命令设置"></a>通过 <code>grub2-set-default 0</code> 命令设置</h3><p>其中 0 来自上一步的 awk 命令</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> grub2-set-default 0</span><br></pre></td></tr></table></figure>

<h3 id="编辑-etc-default-grub-文件"><a href="#编辑-etc-default-grub-文件" class="headerlink" title="编辑 /etc/default/grub 文件"></a>编辑 <code>/etc/default/grub</code> 文件</h3><p>设置 GRUB_DEFAULT&#x3D;0，表示使用上一步的 awk 命令显示的编号为 0 的内核作为默认内核</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># vi /etc/default/grub</span></span><br><span class="line"></span><br><span class="line">&gt; GRUB_TIMEOUT=5</span><br><span class="line">&gt; GRUB_DISTRIBUTOR=<span class="string">&quot;<span class="subst">$(sed &#x27;s, release .*$,,g&#x27; /etc/system-release)</span>&quot;</span></span><br><span class="line">&gt; GRUB_DEFAULT=0</span><br><span class="line">&gt; GRUB_DISABLE_SUBMENU=<span class="literal">true</span></span><br><span class="line">&gt; GRUB_TERMINAL_OUTPUT=<span class="string">&quot;console&quot;</span></span><br><span class="line">&gt; GRUB_CMDLINE_LINUX=<span class="string">&quot;crashkernel=auto console=ttyS0 console=tty0 panic=5&quot;</span></span><br><span class="line">&gt; GRUB_DISABLE_RECOVERY=<span class="string">&quot;true&quot;</span></span><br><span class="line">&gt; GRUB_TERMINAL=<span class="string">&quot;serial console&quot;</span></span><br><span class="line">&gt; GRUB_TERMINAL_OUTPUT=<span class="string">&quot;serial console&quot;</span></span><br><span class="line">&gt; GRUB_SERIAL_COMMAND=<span class="string">&quot;serial --speed=9600 --unit=0 --word=8 --parity=no --stop=1&quot;</span></span><br></pre></td></tr></table></figure>

<h2 id="生成-grub-配置文件并重启"><a href="#生成-grub-配置文件并重启" class="headerlink" title="生成 grub 配置文件并重启"></a>生成 grub 配置文件并重启</h2><p>下一步，通过 <code>gurb2-mkconfig</code> 命令创建 grub2 的配置文件，然后重启</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sudo</span> grub2-mkconfig -o /boot/grub2/grub.cfg</span><br><span class="line"><span class="built_in">sudo</span> reboot</span><br></pre></td></tr></table></figure>

<h2 id="验证"><a href="#验证" class="headerlink" title="验证"></a>验证</h2><p>通过 <code>uname -r</code> 查看，可以发现已经生效了。</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># uname -r</span></span><br><span class="line">4.15.6-1.el7.elrepo.x86_64</span><br></pre></td></tr></table></figure>

<h1 id="删除旧内核-可选"><a href="#删除旧内核-可选" class="headerlink" title="删除旧内核 (可选)"></a>删除旧内核 (可选)</h1><p>内核有两种删除方式：通过 <code>yum remove</code> 命令或通过 <code>yum-utils</code> 工具。</p>
<h2 id="通过-yum-remove-命令"><a href="#通过-yum-remove-命令" class="headerlink" title="通过 yum remove 命令"></a>通过 <code>yum remove</code> 命令</h2><p>查看系统中全部的内核：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># rpm -qa | grep kernel</span></span><br><span class="line">kernel-tools-libs-3.10.0-514.26.2.el7.x86_64</span><br><span class="line">kernel-ml-4.15.6-1.el7.elrepo.x86_64</span><br><span class="line">kernel-3.10.0-327.el7.x86_64</span><br><span class="line">kernel-tools-3.10.0-514.26.2.el7.x86_64</span><br><span class="line">kernel-headers-3.10.0-514.26.2.el7.x86_64</span><br><span class="line">kernel-3.10.0-514.26.2.el7.x86_64</span><br></pre></td></tr></table></figure>

<p>删除旧内核的 RPM 包</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum remove kernel-tools-libs-3.10.0-514.26.2.el7.x86_64 kernel-3.10.0-327.el7.x86_64 kernel-tools-3.10.0-514.26.2.el7.x86_64 kernel-headers-3.10.0-514.26.2.el7.x86_64 kernel-3.10.0-514.26.2.el7.x86_64</span><br></pre></td></tr></table></figure>

<h2 id="通过-yum-utils-工具"><a href="#通过-yum-utils-工具" class="headerlink" title="通过 yum-utils 工具"></a>通过 <code>yum-utils</code> 工具</h2><p>如果安装的内核不多于 <code>3</code> 个，<code>yum-utils</code> 工具不会删除任何一个。只有在安装的内核大于 <code>3</code> 个时，才会自动删除旧内核。</p>
<h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install yum-utils</span><br></pre></td></tr></table></figure>

<h3 id="删除"><a href="#删除" class="headerlink" title="删除"></a>删除</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">package-cleanup --oldkernels</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wechatpay.jpg" alt="Jaron Chim 微信">
        <span>微信</span>
      </div>
      <div>
        <img src="/images/alipay.jpg" alt="Jaron Chim 支付宝">
        <span>支付宝</span>
      </div>

  </div>
</div>

          <div class="post-tags">
              <a href="/tags/linux/" rel="tag"># linux</a>
              <a href="/tags/centOS/" rel="tag"># centOS</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2021/12/11/Rancher-1-6-%E5%BF%AB%E9%80%9F%E5%AE%89%E8%A3%85%E6%8C%87%E5%8D%97/" rel="prev" title="Rancher 1.6 快速安装指南">
                  <i class="fa fa-angle-left"></i> Rancher 1.6 快速安装指南
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2023/07/07/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8-Docker-%E6%9E%84%E5%BB%BA%E4%B8%80%E4%B8%AA%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8/" rel="next" title="如何使用 Docker 构建一个代理服务器">
                  如何使用 Docker 构建一个代理服务器 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">粤ICP备2025405034号-1 </a>
  </div>
  <div class="copyright">
    &copy; 2016 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-user"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Jaron Chim</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>
  <div class="sidebar-dimmer"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>

</body>
</html>
